package data;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;

import rm2.DRSserverinit;

public class ItemList 
{
	private String item;
	private int capacity;
	DRSserverinit drSserverinit;
	
	public ItemList(String item, int capacity,DRSserverinit drSserverinit) 
	{
		this.drSserverinit=drSserverinit;
		this.item = item;
		this.capacity = capacity;
	
	}
	
	//getting the values
	public String getItem()
	{
		return this.item;
	}
	
	public int getCapacity()
	{
		return this.capacity;
	}
	
	/*public String getPrerequisite()
	{
		return prerequisite;
	}
	
	public String getCorequisite()
	{
		return corequisite;
	}*/
	
	// Setting the values
	public void setItem(String item)
	{
		this.item = item;
	}
	
	public void setCapacity(int capacity)
	{
		this.capacity = capacity;
	}
	
	
	
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(this.item + " ");
		//sb.append(" ");
		sb.append(this.capacity + " ");
		
		return sb.toString();
	}
	
	public void writeItemListFile() throws IOException
	{
	    FileWriter fstream = new FileWriter("input" + File.separator + "ItemList");
    	BufferedWriter out = new BufferedWriter(fstream);
	    //out.write("Customer ID:" + customer_id);
    	Iterator it = drSserverinit.slist.keySet().iterator(); 
    	
    	while(it.hasNext()) 
    	{ 
    		String key = (String) it.next(); 
    		int val = drSserverinit.slist.get(key).getCapacity();
    		
    		out.write(key);
    		out.write(val);
    	}
    	
    	out.close();
    	fstream.close();
    	
	}
	
	

}
